
#ifndef _SINGLETON_H
#define _SINGLETON_H

#include "Scoped_Ptr.h"

/**
 * \namespace bga
 * \brief API namespace
 */
namespace bga
{

/*! \class Singleton
*   \brief Base Class for a Singleton Object
*/
template<typename T>
class Singleton
{
    private:
        static bga::Scoped_Ptr<T> instance;   ///!< single instance of the Singleton

    private:
        Singleton operator =(Singleton&);   ///!< declaration of that operator only to forbid the use
        Singleton(Singleton&);              ///!< declaration of that copy constructor only to forbid the use

    protected:
        Singleton() {}      ///!< Singleton Class constructor
        virtual ~Singleton() {};   ///!< Singleton Class destructor

    public:
        /*!
        *   \fn static T& getInstance()
        *   \brief create or return an instanceance of a T Object
        *   \return the only instanceance of the Singleton
        */
        static T& getInstance();
};

/** End of the Singleton Class declaration **/

/** definition of the static var**/
template <typename T> bga::Scoped_Ptr<T> Singleton<T>::instance(NULL);

template<typename T>
T& Singleton<T>::getInstance()
{
    if(!(Singleton::instance))
    {
        delete (Singleton::instance.get()); /// Is it really useful?
        (Singleton::instance).reset(new T);
    }
    return *(Singleton::instance);
}

}

#endif // ndef _SINGLETON_H
